package Offer;

/**
 * 删除链表的节点
 * @author 是阿秋啊
 * @date 2022/04/09 21:57
 **/
public class Num18 {
    public ListNode deleteNode(ListNode head, int val) {
        if (head == null) {
            return null;
        }
        if (head.val == val) {
            return head.next;
        }
        ListNode pre = head;
        while (pre.next != null) {
            if (pre.next.val == val) {
                pre.next = pre.next.next;
            }
            pre = pre.next;
        }
        return head;
    }
}
